package com.seal.tsms.school.controller;

import com.seal.tsms.base.controller.BaseController;
import com.seal.tsms.base.service.BaseService;
import com.seal.tsms.school.entity.WorkInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

/**
 * Created by dengsimin on 2016/1/21.
 */

@Controller
@RequestMapping("school/workInfo")
public class WorkInfoController  extends BaseController<WorkInfo,String> {

   @RequestMapping(value="/add",method = RequestMethod.GET)   //get
    public String create(){
        return  "school/workInfo/add";
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public String save(@ModelAttribute("work") WorkInfo work,RedirectAttributes attr){
        getSelfService().save(work);
        attr.addAttribute("id",work.getId());
        attr.addAttribute("msg","工作状况添加成功！");
        return "redirect:school/workInfo/show.do";
    }

    @RequestMapping("/show")
    public String show(@RequestParam String id, ModelMap  model){
        model.addAttribute("work",getSelfService().get(id));
        return "school/workInfo/show";
    }

    @Override
    @Autowired
    @Qualifier("workServiceImpl")
    public void setSelfService(BaseService<WorkInfo, String> selfService) {
        super.setSelfService(selfService);
    }
}
